#ifndef _SUB_CAN_H_
#define _SUB_CAN_H_

#include <stdint.h>

#define BMU_MAXMODENUM_CFG 3
#define BMU_MAXNUM_CFG 8
#define BMU_BRANCH_CFG 4
#define BMU_MAXVOL_CFG 18
#define BMU_MAXTMP_CFG 8

typedef enum
{
    EM_CTRL_TYPE_IO = 1,
    EM_CTRL_TYPE_485,
    EM_CTRL_TYPE_balvol,
    EM_CTRL_TYPE_loadvol,
    EM_CTRL_TYPE_eep,
}EM_CTRL_TYPE_t;

typedef enum
{
    EM_IO_1 = 1,
    EM_IO_2 ,
    EM_IO_3 ,
    EM_IO_4 ,
    EM_IO_5 ,
    EM_IO_6 ,
    EM_IO_7 ,
    EM_IO_8 ,
    EM_IO_9 ,
    EM_IO_10 ,
    EM_IO_11 ,
    EM_IO_12 ,
    EM_IO_PW,
    EM_IO_BP,
    EM_IO_LP,
}EM_IO_CHL_t;

typedef enum
{
    EM_IO_H = 1,
    EM_IO_L ,
}EM_IO_ST_t;

#pragma pack(push)
#pragma pack(1)
typedef union
{
    uint8_t data[64];
            /*BMU*/
    struct
    {
        uint8_t life;

        uint16_t in_FB1:1;
        uint16_t in_FB2:1;
        uint16_t in_FB3:1;
        uint16_t in_FB4:1;
        uint16_t in_FB5:1;
        uint16_t in_FB6:1;
        uint16_t in_FB7:1;
        uint16_t in_FB8:1;
        uint16_t in_FB9:1;
        uint16_t in_FB10:1;
        uint16_t in_FB11:1;
        uint16_t in_FB12:1;
        uint16_t in_chg: 1;
        uint16_t in_on : 1;
        uint16_t in_cc2: 1;
        uint16_t in_pw : 1;
        
        uint8_t  in_bp :1;
        uint8_t  in_lp :1;
        uint8_t  :6;        
        
        uint8_t tmp1;
        uint8_t tmp2;
        uint8_t tmp3;
        uint8_t tmp4;
        uint8_t tmp5;
        uint8_t tmp6;
        uint8_t tmpChip;
        uint16_t Vrefin;
        uint16_t Hall1Vol;
        uint16_t Hall2Vol;
        uint16_t Hall3Vol;
        uint16_t Hall4Vol;        
        
        uint8_t txST485: 1;
        uint8_t rxST485: 1;
        uint8_t wSTeep : 1;
        uint8_t rSTeep : 1;
        uint8_t: 4;

        uint16_t batvol;
        uint16_t loadvol;
    }mes;
}SendMES01_t;

typedef union
{
    uint8_t data[64];
    struct app_sub_can
    {
        uint8_t ctrl_type;
        uint8_t io_ch:4;
        uint8_t io_st:4;
        uint8_t u8485testen;
        uint8_t batvoltesten;
        uint8_t loadvoltesten;
        uint8_t eeptesten;
    }mes;
}ReciveMes01_t;

#pragma pack(pop)

typedef struct
{
    EM_CTRL_TYPE_t  ctrl_type;
    EM_IO_CHL_t     io_ch;
    EM_IO_ST_t      io_st;
    SendMES01_t     txMes1;
    ReciveMes01_t   rxMes1;
}APP_sub_can_t;

void app_sub_can_rx_run(void);
void app_sub_can_tx_run(void);
extern APP_sub_can_t subCan;

#endif

